local raveChildren
local t = Def.ActorFrame {};
local exget = GAMESTATE:HasEarnedExtraStage();
local ex = GAMESTATE:IsExtraStage();
local ex2 = GAMESTATE:IsExtraStage2();
local course = GAMESTATE:IsCourseMode();
	
t[#t+1] = LoadActor("_eval display") .. {
		InitCommand=function(self) self:diffusealpha(1) end;
		OnCommand=function(self)
			if exget and ex2 then
				self:sleep(3.3):queuecommand("Vibe1")
			end
		end;
		Vibe1Command=function(self) self:vibrate():effectmagnitude(3,3,3):sleep(0.2):queuecommand("Vibe2") end;
		Vibe2Command=function(self) self:vibrate():effectmagnitude(6,6,6):sleep(0.2):queuecommand("Vibe3") end;
		Vibe3Command=function(self) self:vibrate():effectmagnitude(9,9,9):sleep(0.2):queuecommand("Vibe4") end;
		Vibe4Command=function(self) self:vibrate():effectmagnitude(12,12,12):sleep(0.2):queuecommand("Vibe5") end;
		Vibe5Command=function(self) self:vibrate():effectmagnitude(15,15,15):sleep(0.2):queuecommand("Vibe6") end;
		Vibe6Command=function(self) self:vibrate():effectmagnitude(18,18,18):sleep(0.2):queuecommand("Vibe7") end;
		Vibe7Command=function(self) self:vibrate():effectmagnitude(21,21,21):sleep(0.1):queuecommand("Vibe0") end;
		Vibe0Command=function(self) self:vibrate():effectmagnitude(1,1,1)end;
			
	};
t[#t+1] = LoadActor("_music") .. {
	OnCommand=function(self)
		if exget then
			self:sleep(0.2):queuecommand("Play2")
		elseif ex2 and not exget then
			self:sleep(0.2)
		elseif not exget then
			self:sleep(0.2):queuecommand("Play")
		end
	end;	
	PlayCommand=function(self) self:play() end;
	Play2Command=function(self) self:play():sleep(3):queuecommand("ButWait") end;
	ButWaitCommand=function(self) self:stop() end;
	OffCommand=function(self) self:sleep(0.6):queuecommand("Stop") end;
	StopCommand=function(self) self:stop() end;
};

t[#t+1] = LoadActor("_exwarning")..{
	Condition=ex and exget;
	OnCommand=function(self) self:sleep(4.3):queuecommand("Play") end;
	PlayCommand=function(self) self:play() end;
};
t[#t+1] = LoadActor("_ex_amb")..{
	Condition=ex and exget;
	OnCommand=function(self) self:sleep(8.5):queuecommand("Play") end;
	PlayCommand=function(self) self:play() end;
};

t[#t+1] = LoadActor("_omesmusic")..{
	Condition=ex2;
	OnCommand=function(self)
		if exget then
			self:sleep(7.5):queuecommand("Play")
		else
			self:sleep(0.2):queuecommand("Play")
		end
	end;
	PlayCommand=function(self) self:play() end;
};
	
if not GAMESTATE:IsCourseMode() then
local song = GAMESTATE:GetCurrentSong();
local sname = song:GetDisplayMainTitle();
local ssname = song:GetDisplaySubTitle();
if song then
	if song:HasJacket() then
		t[#t+1] = LoadActor("_jacketframe") .. {
			InitCommand=function(self) self:x(SCREEN_CENTER_X):y(SCREEN_CENTER_Y-50):zoom(0.76):diffusealpha(1) end;
			OnCommand=function(self) self:zoomy(0):sleep(0.2):linear(0.1):zoomy(0.76)
				if exget and ex2 then
					self:sleep(3):queuecommand("Vibe1")
				end
			end;
			OffCommand=function(self) self:sleep(0.2):linear(0.1):zoomy(0) end;
			Vibe1Command=function(self) self:vibrate():effectmagnitude(3,3,3):sleep(0.2):queuecommand("Vibe2") end;
			Vibe2Command=function(self) self:vibrate():effectmagnitude(6,6,6):sleep(0.2):queuecommand("Vibe3") end;
			Vibe3Command=function(self) self:vibrate():effectmagnitude(9,9,9):sleep(0.2):queuecommand("Vibe4") end;
			Vibe4Command=function(self) self:vibrate():effectmagnitude(12,12,12):sleep(0.2):queuecommand("Vibe5") end;
			Vibe5Command=function(self) self:vibrate():effectmagnitude(15,15,15):sleep(0.2):queuecommand("Vibe6") end;
			Vibe6Command=function(self) self:vibrate():effectmagnitude(18,18,18):sleep(0.2):queuecommand("Vibe7") end;
			Vibe7Command=function(self) self:vibrate():effectmagnitude(21,21,21):sleep(0.1):queuecommand("Vibe0") end;
			Vibe0Command=function(self) self:vibrate():effectmagnitude(1,1,1) end;
		};
	elseif song:HasBanner() or song:HasBanner() == false then
		t[#t+1] = LoadActor("_commonbannerframe") .. {
			InitCommand=function(self) self:x(SCREEN_CENTER_X):y(SCREEN_CENTER_Y-10):zoom(0.76):diffusealpha(1) end;
			OnCommand=function(self) self:zoomy(0):sleep(0.2):linear(0.1):zoomy(0.78)
				if exget and ex2 then
					self:sleep(3):queuecommand("Vibe1")
				end
			end;
			OffCommand=function(self) self:sleep(0.2):linear(0.1):zoomy(0) end;
			Vibe1Command=function(self) self:vibrate():effectmagnitude(3,3,3):sleep(0.2):queuecommand("Vibe2") end;
			Vibe2Command=function(self) self:vibrate():effectmagnitude(6,6,6):sleep(0.2):queuecommand("Vibe3") end;
			Vibe3Command=function(self) self:vibrate():effectmagnitude(9,9,9):sleep(0.2):queuecommand("Vibe4") end;
			Vibe4Command=function(self) self:vibrate():effectmagnitude(12,12,12):sleep(0.2):queuecommand("Vibe5") end;
			Vibe5Command=function(self) self:vibrate():effectmagnitude(15,15,15):sleep(0.2):queuecommand("Vibe6") end;
			Vibe6Command=function(self) self:vibrate():effectmagnitude(18,18,18):sleep(0.2):queuecommand("Vibe7") end;
			Vibe7Command=function(self) self:vibrate():effectmagnitude(21,21,21):sleep(0.1):queuecommand("Vibe0") end;
			Vibe0Command=function(self) self:vibrate():effectmagnitude(1,1,1) end;
		};
	end
end
t[#t+1] = LoadFont("_pixellari 32px")..{ -- Song name
	InitCommand=function(self) self:xy(SCREEN_CENTER_X,SCREEN_CENTER_Y+40):zoom(0.5):diffusealpha(0) end;
	OnCommand=function(self) self:settext(sname):sleep(0.6):linear(0.2):diffusealpha(1)
		if exget and ex2 then
			self:sleep(2.6):queuecommand("Vibe1")
		end
	end;
	OffCommand=function(self) self:linear(0.2):diffusealpha(0) end;
	Vibe1Command=function(self) self:vibrate():effectmagnitude(3,3,3):sleep(0.2):queuecommand("Vibe2") end;
	Vibe2Command=function(self) self:vibrate():effectmagnitude(6,6,6):sleep(0.2):queuecommand("Vibe3") end;
	Vibe3Command=function(self) self:vibrate():effectmagnitude(9,9,9):sleep(0.2):queuecommand("Vibe4") end;
	Vibe4Command=function(self) self:vibrate():effectmagnitude(12,12,12):sleep(0.2):queuecommand("Vibe5") end;
	Vibe5Command=function(self) self:vibrate():effectmagnitude(15,15,15):sleep(0.2):queuecommand("Vibe6") end;
	Vibe6Command=function(self) self:vibrate():effectmagnitude(18,18,18):sleep(0.2):queuecommand("Vibe7") end;
	Vibe7Command=function(self) self:vibrate():effectmagnitude(21,21,21):sleep(0.1):queuecommand("Vibe0") end;
	Vibe0Command=function(self) self:vibrate():effectmagnitude(1,1,1)end;
};
t[#t+1] = LoadFont("_pixellari 32px")..{ -- Song subtitle
	InitCommand=function(self) self:xy(SCREEN_CENTER_X,SCREEN_CENTER_Y+55):zoom(0.4):diffusealpha(0) end;
	OnCommand=function(self) self:settext(ssname):sleep(0.6):linear(0.2):diffusealpha(1)
		if exget and ex2 then
			self:sleep(2.6):queuecommand("Vibe1")
		end
	end;
	OffCommand=function(self) self:linear(0.2):diffusealpha(0) end;
	Vibe1Command=function(self) self:vibrate():effectmagnitude(3,3,3):sleep(0.2):queuecommand("Vibe2") end;
	Vibe2Command=function(self) self:vibrate():effectmagnitude(6,6,6):sleep(0.2):queuecommand("Vibe3") end;
	Vibe3Command=function(self) self:vibrate():effectmagnitude(9,9,9):sleep(0.2):queuecommand("Vibe4") end;
	Vibe4Command=function(self) self:vibrate():effectmagnitude(12,12,12):sleep(0.2):queuecommand("Vibe5") end;
	Vibe5Command=function(self) self:vibrate():effectmagnitude(15,15,15):sleep(0.2):queuecommand("Vibe6") end;
	Vibe6Command=function(self) self:vibrate():effectmagnitude(18,18,18):sleep(0.2):queuecommand("Vibe7") end;
	Vibe7Command=function(self) self:vibrate():effectmagnitude(21,21,21):sleep(0.1):queuecommand("Vibe0") end;
	Vibe0Command=function(self) self:vibrate():effectmagnitude(1,1,1)end;
};

t[#t+1] = Def.ActorFrame {
	InitCommand=function(self)
		if song:HasJacket() then
			self:xy(SCREEN_CENTER_X,SCREEN_CENTER_Y-50)
		elseif song:HasBanner() then
			self:xy(SCREEN_CENTER_X,SCREEN_CENTER_Y-10)
		else -- no cover image at all; assume banner
			self:xy(SCREEN_CENTER_X,SCREEN_CENTER_Y-10)
		end
	end;
	OnCommand=function(self) self:diffusealpha(0):zoomy(0):sleep(0.5):linear(0.3):diffusealpha(1):zoomy(1)
		if exget and ex2 then
			self:sleep(2.6):queuecommand("Vibe1")
		end
	end;
	OffCommand=function(self) self:linear(0.2):zoomy(0):diffusealpha(0) end;
	Vibe1Command=function(self) self:vibrate():effectmagnitude(3,3,3):sleep(0.2):queuecommand("Vibe2") end;
	Vibe2Command=function(self) self:vibrate():effectmagnitude(6,6,6):sleep(0.2):queuecommand("Vibe3") end;
	Vibe3Command=function(self) self:vibrate():effectmagnitude(9,9,9):sleep(0.2):queuecommand("Vibe4") end;
	Vibe4Command=function(self) self:vibrate():effectmagnitude(12,12,12):sleep(0.2):queuecommand("Vibe5") end;
	Vibe5Command=function(self) self:vibrate():effectmagnitude(15,15,15):sleep(0.2):queuecommand("Vibe6") end;
	Vibe6Command=function(self) self:vibrate():effectmagnitude(18,18,18):sleep(0.2):queuecommand("Vibe7") end;
	Vibe7Command=function(self) self:vibrate():effectmagnitude(21,21,21):sleep(0.1):queuecommand("Vibe0") end;
	Vibe0Command=function(self) self:vibrate():effectmagnitude(1,1,1)end;
	Def.Sprite {
		name="SongBanner";
		OnCommand=function(self) 
			 local song = GAMESTATE:GetCurrentSong(); 
				if song then
					if song:HasJacket() then
						self:Load(song:GetJacketPath()):scaletoclipped(200,200)
					elseif song:HasBanner() then
						self:Load(song:GetBannerPath()):scaletoclipped(256,80)
					else
						self:Load(THEME:GetPathG("Common fallback", "banner")):scaletoclipped(256,80)
					end
					self:zoom(0.75)
				else
					self:diffusealpha(0)
			end
		end;
	};
};
else
t[#t+1] = Def.ActorFrame {
	LoadActor("_jacketframe") .. {
		InitCommand=function(self) self:x(SCREEN_CENTER_X):y(SCREEN_BOTTOM-160):zoom(0.76):diffusealpha(1) end;
		OnCommand=function(self) self:zoomy(0):sleep(0.2):linear(0.1):zoomy(0.78) end;
		OffCommand=function(self) self:sleep(0.1):linear(0.1):zoomy(0) end;
	};
	Def.Sprite {
		name="CourseBanner";
		OnCommand=function(self) 
			self:visible(true)
			local course = GAMESTATE:GetCurrentCourse();
			if course:HasBanner() then
				self:Load(course:GetBannerPath()):x(SCREEN_CENTER_X):y(SCREEN_BOTTOM-160)
			else
				self:Load(THEME:GetPathG("Common fallback", "banner")):x(SCREEN_CENTER_X):y(SCREEN_BOTTOM-110)
			end
			self:scaletoclipped(150,150):zoomy(0):sleep(0.4):linear(0.2):zoomy(1)
		end;
		OffCommand=function(self) self:linear(0.1):zoomy(0) end;
	};
	LoadFont("_pixellari 32px") .. {
		InitCommand=function(self) self:Center():y(SCREEN_BOTTOM-60):zoom(1):diffuse(color("#C4E9F5")):strokecolor(color("#000000")) end;
		OnCommand=function(self) self:diffusealpha(0):sleep(0.3):smooth(0.3):diffusealpha(1) end;
		OffCommand=function(self) self:smooth(0.2):zoomx(0.7):diffusealpha(0) end;
		Text=GAMESTATE:GetCurrentCourse():GetDisplayFullTitle()
	};
};
end;

t[#t+1] = Def.ActorFrame {
		Def.Quad {
			InitCommand=function(self) self:FullScreen():diffuse(color("#000000")):diffusealpha(0) end;
			OffCommand=function(self) self:sleep(1.2):decelerate(0.4):diffusealpha(1) end;
		};
	};

t[#t+1] = Def.ActorFrame {
		Def.ActorFrame{
		Name="RaveMessages";
		InitCommand=function(self)
			raveChildren = self:GetChildren()
			self:visible(GAMESTATE:GetPlayMode() == 'PlayMode_Rave')

			raveChildren.P1Win:visible(false)
			raveChildren.P2Win:visible(false)
			raveChildren.Draw:visible(false)
		end;
		OnCommand=function(self)
			local p1Win = GAMESTATE:IsWinner(PLAYER_1)
			local p2Win = GAMESTATE:IsWinner(PLAYER_2)

			if GAMESTATE:IsWinner(PLAYER_1) then
				raveChildren.P1Win:visible(true)
			elseif GAMESTATE:IsWinner(PLAYER_2) then
				raveChildren.P2Win:visible(true)
			else
				raveChildren.Draw:visible(true)
			end
		end;

		LoadActor(THEME:GetPathG("_rave result","P1"))..{
			Name="P1Win";
			InitCommand=function(self) self:Center() end;
			OnCommand=function(self)
				self:diffusealpha(0):zoom(1):smooth(0.6):zoom(0.75):diffusealpha(1):sleep(1):decelerate(0.6):addy(70):zoom(0.25)
			end;
			OffCommand=function(self) self:decelerate(0.3):diffusealpha(0) end;
		};
		LoadActor(THEME:GetPathG("_rave result","P2"))..{
			Name="P2Win";
			InitCommand=function(self) self:Center() end;
			OnCommand=function(self)
				self:diffusealpha(0):zoom(1):smooth(0.6):zoom(0.75):diffusealpha(1):sleep(1):decelerate(0.6):addy(70):zoom(0.25)
			end;
			OffCommand=function(self) self:decelerate(0.3):diffusealpha(0) end;
		};
		LoadActor(THEME:GetPathG("_rave result","draw"))..{
			Name="Draw";
			InitCommand=function(self) self:Center() end;
			OnCommand=function(self)
				self:diffusealpha(0):zoom(1):smooth(0.6):zoom(0.75):diffusealpha(1):sleep(1):decelerate(0.6):addy(70):zoom(0.25)
			end;
			OffCommand=function(self) self:decelerate(0.3):diffusealpha(0) end;
		};
	};
};
		
return t